#include "vertexTreeItem.h"
#include "src/point.h"

VertexTreeItem::VertexTreeItem(QTreeWidgetItem *_parentItem, Vertex *_v) : TreeItem(_parentItem), v(_v){
    setFlags(Qt::ItemIsSelectable);
    QString str = "Vertice ";
    str.append(QString::number(v->getID()));
    setText(0, str);

    TreeItem *itemPoint = new TreeItem(this);
    Point p = v->getPoint();
    str = "( ";
    str.append(QString::number(p.x));
    str.append(", ");
    str.append(QString::number(p.y));
    str.append(", ");
    str.append(QString::number(p.z));
    str.append(" )");
    itemPoint->setText(0, str);


    if(v->isSelected()) setSelected(true);
    else setSelected(false);
}

VertexTreeItem::~VertexTreeItem(){
}

void VertexTreeItem::updateVertex(Vertex *_v){
    v = _v;
}

Vertex *VertexTreeItem::getVertex(){
    return v;
}

void VertexTreeItem::select(){
    if(v->isSelected()){
        v->select(false);
        setSelected(false);
    }else{
        v->select(true);
        setSelected(true);
    }
    emit selected(v);
}
